package com.surveycomp.test.unittest;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import javax.jdo.PersistenceManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.junit.After;
import org.junit.Before;

import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalMailServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;
import com.surveycomp.datastore.PMF;

public abstract class ServletTesting {
	protected HttpServletRequest req;
	protected HttpServletResponse resp;
	protected HttpSession session;

	protected static final LocalMailServiceTestConfig LOCAL_MAIL_SERVICE_TEST_CONFIG = new LocalMailServiceTestConfig();
	protected static final LocalDatastoreServiceTestConfig LOCAL_DATASTORE_SERVICE_TEST_CONFIG = new LocalDatastoreServiceTestConfig();
	protected final LocalServiceTestHelper helper = new LocalServiceTestHelper(
			LOCAL_DATASTORE_SERVICE_TEST_CONFIG, LOCAL_MAIL_SERVICE_TEST_CONFIG);
	protected PersistenceManager pm;
	protected ServletContext servletcontext;
	protected RequestDispatcher requestDispatcher;

	@Before
	public void setUp() {
		helper.setUp();
		req = mock(HttpServletRequest.class);
		resp = mock(HttpServletResponse.class);
		session = mock(HttpSession.class);
		pm = PMF.get().getPersistenceManager();
		servletcontext = mock(ServletContext.class);
		requestDispatcher = mock(RequestDispatcher.class);
		when(servletcontext.getRequestDispatcher("/facechallenge")).thenReturn(
				requestDispatcher);
		when(req.getSession()).thenReturn(session);
		when(req.getSession(true)).thenReturn(session);
	}

	@After
	public void tearDown() {
		helper.tearDown();
	}
}
